{extend name="platform/base" /}
{block name="resources"}
<!-- <link rel="stylesheet" type="text/css" href="ADMIN_CSS/haidao.css"> -->
<!-- <link rel="stylesheet" type="text/css" href="ADMIN_CSS/admin.css"> -->
<style>
.btn-test{font-family:"microsoft yahei";border-radius:4px;padding:5px 20px;background-color:#51A351;color:#FFF;margin:0 10px;border:none}
.Switch_FlatCircular{line-height:30px}
.left_main{width:23%;float:left;border:1px solid #E3E3E3;height:524px}
.left_main ul{margin:10px}
.left_main ul a.active{color:#11B9ED}
.left_main ul a:hover{color:#11B9ED}
.leftcheckbox{float:right}
.left_main li{line-height:30px;padding:2px 6px;border:1px dotted #E3E3E3;margin-bottom:10px;list-style-type:none}
.left_main ul a{color:#666}
a:hover{color:#11B9ED}
.right_main{width:75%;float:right;border:1px solid #E3E3E3;height:400px}
.main-top{height:30px;line-height:30px;padding:0 10px;color:#666;border-bottom:1px solid #E3E3E3;margin-bottom:15px}
.email_title{width:81px;line-height:40px;float:left;padding-left:10px}
.edit_bat{width:250px;float:left;margin-left:20px;line-height:40px}
.save{clear:both;text-align:center;margin-top:10px;display:inline-block;width:100%}
a.submit,input.submit,input[type=submit]{display:inline-block}
.back{background:#e5e5e5;border:0;height:30px;width:66px}
.rightlist{clear:both;content:'';display:inline-block}
.right-item{width:12%}
.itemlist{padding:0 2px;margin:5px;float:left;text-align:center;color:#666}
.title-item{height:40px;border-top:1px solid #E3E3E3;color:#666}
.template-message{height:40px;line-height:40px;border:1px solid #e5e5e5;border-bottom:none}
h1{width:2px;height:20px;float:left;background-color:#11B9ED}
.active{color:#11B9ED}
.tab-pane{clear:both;content:''}
.msg{display:inline-block;width:100%;color:#FF8400;height:40px;line-height:40px;padding-left:10px}
.senditem{border:1px solid #11B9ED;margin:9px;border-radius:3px;width:30%}
.qianming{display:inline-block;line-height:40px;margin-left:10px;color:#666;width:100%}
.bl{color:#666;margin-left:10px;display:inline-block;line-height:35px;width:100%}
input[type=text]{vertical-align:middle;margin-bottom:0}
</style>
{/block}
{block name="main"}
<!-- 邮箱设置 -->
<input type="hidden" id="curr_selectid" value="{$template_select.template_code}"/>
<div class="set-style">
<div class="template-message"><h1></h1><p style="width:90%;margin: 9px 7px 10px;">短信通知模板</p></div>
	<div class="tab-pane active">
		<div class="left_main">
			<ul>
				{volist name="template_type_list" id="template_item"}
					<a href="javascript:void(0);" onclick="template_onclick(this);" id="{$template_item.template_code}" style="text-decoration: none;" class="{$i == 1?'active':null}">
						<li>{$template_item.template_name}
<!-- 							<span class="leftcheckbox"> -->
<!-- 							{if condition="$template_item.is_enable eq 1"} -->
<!-- 								<input id="adminCode" type="checkbox" class="checkbox" checked="checked" name="{$template_item.template_code}" onchange="check_change(this);"/> -->
<!-- 							{else/} -->
<!-- 								<input id="adminCode" type="checkbox" class="checkbox" onchange="check_change(this);" name="{$template_item.template_code}"/> -->
<!-- 							{/if} -->
<!-- 							</span> -->
							<label class="switch" style="float:right;">
								<input type="checkbox" id="adminCode" {if condition="$template_item.is_enable eq 1"}checked="checked"{/if} name="{$template_item.template_code}" onchange="check_change(this);">
								<span></span>
							</label>
						</li>
					</a>
				{/volist}
			</ul>
		</div>
		<div class="right_main">
			<div class="main-top">您正在编辑<a href="javascript:;" id="update_nameid" style="color:#11B9ED;"></a>通知模板</div>
			<div class="qianming"><div style="width:75px;float:left;">模板ID：</div><input type="text" name="" id="template_titleid" value="{$template_select.template_title}" style="margin-right: 15px;height: 30px;line-height: 30px;"/><span style="font-size:13px;">须于阿里大鱼的模板ID一致，否则无效!</span></div>
			<div class="qianming"><div style="width:75px;float:left;">短信签名：</div><input type="text" name="" id="signNameid" style="margin-right: 15px;height: 30px;line-height: 30px;" value="{$template_select.sign_name	}"/><span style="font-size:13px;">与阿里大鱼内短信签名保持一致!</span></div>
			<div class="bl">
				<div style="width:75px;float:left;">可用变量：</div>
				<div style="width:88%;float: left;font-size:13px;" id="user_variable">
					{foreach name="template_item_list" item="item_obj"}
						{$item_obj.replace_name}({$item_obj.item_name}),
					{/foreach}
				</div>
			</div>
			
		</div>
	</div>
	<div class="save">
		<input type="submit" value="保存" style="margin-right: 20px;width: 58px;height: 30px;border: 0;background-color: #5BB75B;color: #fff;"" onclick="template_submit();"/>
		<a href="{:__URL('PLATFORM_MAIN/config/notifyindex')}">
			<input type="button" value="返回" class="back" style="width: 66px;height:30px;"/>
		</a>
	</div>
								
</div>
{include file="platform/openDialog" /}

<script type="text/javascript">
var $template_array={$template_json};
var $template_send_item={$template_send_item_json};
var $is_first=1;
var $curr_select=$("#curr_selectid").val();
$("#"+$curr_select).click();
/**
 * 左边模板菜单的点击函数
 */
function template_onclick(event){
	$(event).parent('ul').find('a').removeClass('active');
	$(event).addClass('active');
	//处理新的以前 将上次改动的保存
	var $deal_type="";
	var $deal_title="";
	var $sign_name="";
	if($is_first==0){
		$deal_type=$("#curr_selectid").val();
		$deal_title=$("#template_titleid").val();
		$sign_name=$("#signNameid").val();
	}
	$template_type=$(event).attr("id");
	for($i=0; $i<$template_array.length;$i++){
		$template_obj=$template_array[$i];
		$template_obj_type=$template_obj.template_code;
		if($template_obj_type==$deal_type && $is_first==0){
			$template_array[$i].template_title=$deal_title;
			$template_array[$i].sign_name=$sign_name;
		}
		if($template_obj_type==$template_type){
			$("#curr_selectid").val($template_type);
			$("#update_nameid").text($template_obj.template_name);
			$title=$template_obj.template_title;
			$("#template_titleid").val($title);
			$("#signNameid").val($template_obj.sign_name);
		}
		
	}
	$is_first=0;
	get_template_item($template_type);
}
function get_template_item(template_code){
	
	$.ajax({
		type : "post",
        url: "{:__URL('PLATFORM_MAIN/config/getTemplateItem')}",
        data: {"template_code": template_code },
        async : false, // 让它同步执行
        success: function (data) {
        	var $html="";
        	for($i=0;$i<data.length;$i++){
        		$name=data[$i]["item_name"];
        		$replace=data[$i]["replace_name"];
        		if($html==""){
	        		$html=$replace+"("+$name+")";
        		}else{
	        		$html=$html+","+$replace+"("+$name+")";
        		}
        	}
        	$("#user_variable").html($html);
        }
    });
}
/**
 * 开关关闭的点击事件
 */
function check_change(event){
	var $type=$(event).attr("name");
	if($(event).is(":checked")){
		$is_enable=1;
	}else{
		$is_enable=0;
	}
	for($i=0; $i<$template_array.length;$i++){
		$template_obj=$template_array[$i];
		$template_obj_type=$template_obj.template_code;
		if($template_obj_type==$type){
			$template_array[$i].is_enable=$is_enable;
		}
	}
}
function template_submit(){
	var $curr_select=$("#curr_selectid").val();
	$("#"+$curr_select).click();
// 	alert(JSON.stringify($template_array));
	$.ajax({
		type : "post",
        url: "{:__URL('PLATFORM_MAIN/config/updatenotifytemplate')}",
        data: { "type": "sms", "template_data": JSON.stringify($template_array) },
        async : false, // 让它同步执行
        success: function (data) {
        	if (data["code"] > 0) {
				showMessage('success', '提交成功');
				 window.location.href = "{:__URL('PLATFORM_MAIN/config/notifysmstemplate')}";
			}else{
				showMessage('error', '提交失败');
			}	
        }
    });
}
</script>
{/block}